package client.stations;

import client.meteoUtils.Meteo;

import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.XMLParser;

public class Station 
{
	
	private class RTH implements ResponseTextHandler
	{
		private Station stat ;
		
		public RTH(Station stat) 
		{
			this.stat = stat;	
		}

		public void onCompletion(String responseText) 
		{
	    	// creation du document
	    	Document doc = XMLParser.parse(responseText);
	    	
	    	//recuperation du noeud racine
	    	Element elementRacine = doc.getDocumentElement();
	    	
	        // Must do this if you ever use a raw node list that you expect to be
	        // all elements.
	    	XMLParser.removeWhitespace(elementRacine);
	    	
	    	Node nodeMeteo = elementRacine.getElementsByTagName("METEO").item(0) ; 
	    	this.stat.meteo =  new Meteo((Element)nodeMeteo);
	    	
	    	//MeteoPanel.getInstance().setMeteo( this.stat.meteo );
		}
		
	}
	
	private String nom 		; 
	private String XMLurl 	;
	private Meteo meteo		;
	
	public Station(String nom, String lurl)
	{
		super();
		this.nom = nom;
		XMLurl = lurl;
	}

	
	public void retrieveInfos()
	{
		HTTPRequest.asyncGet( this.XMLurl, new RTH(this) );
	}


	public Meteo getMeteo() {
		return meteo;
	}


	public String getNom() {
		return nom;
	}

}
